<?php
namespace User\Controller;
use Api\Controller\BaseApiController;
use User\Model\AreaModel;
use User\Model\CodeModel;
use Message\Core\Openfire;
use User\Model\UserModel;
class ApiotherController extends BaseApiController {
	protected $area_db;
	function _initialize() {
		parent::_initialize();
		$this->area_db = new AreaModel();
	}
	/**
	 * 区域列表
	 */
	function areaList(){
		$area 	= new AreaModel();
		$return = $area->areaList();
		$this->jsonOutput($return);
	}
	/**
	 * 获取验证码
	 */
	function getCode(){
		$code   = new CodeModel();
		$return = $code->getCode();
		$this->jsonOutput($return);
	}
	/**
	 * 验证验证码
	 */
	function checkCode(){
		$code	= new CodeModel();
		$return = $code->checkCode();
		$this->jsonOutput($return);
	}
	/**
	 * 帮助中心
	 */
	function help(){
		$this->text = '';
		if (S('User_help')) $this->text = htmlspecialchars_decode(S('User_help'));
		$this->display('help');
	}
	/**
	 * 注册协议
	 */
	function regist(){
		$this->text = '';
		if (S('User_regist')) $this->text = htmlspecialchars_decode(S('User_regist'));
		$this->display('regist');
	}

    /**
     * 忘记密码
     */
    function forgetPwd(){
        $phone  = I('phone');
        $pwd  = I('pwd');
        $return = D('User')->forgetPwd($phone,$pwd);
        $this->jsonOutput($return);
    }
    /**
     * 银行卡列表
     */
    function cardList(){
        $result=M('card')->order('create_time desc')->select();
        if($result){
            $return =showData($result);
        }else{
            $return = showData(new \stdClass(),'没有银行卡',1);
        }
        $this->jsonOutput($return);
    }


    /**
     * 根据条件进行查询
     * 数据表 trade
     * 字段 id,uid,fuid,score,type,month,create_time
     *
     * @param $uid 通过POST传递方式，请勿使用$_POST进行接收
     *
     * @return $arr JSON格式 code=0 正确，1 异常
     *
     * @explain uid=1，先按照月份进行分类，然后按照type进行倒序
     *
     *
     * [
     *      data:[
     *         {
     *          month:
     *          list:[
     *                  {},
     *                  {},
     *              ]
     *          }
     *          {},
     *      ],
     *      state:{
     *              code:
     *              msg:
     *          }
     * ]
     */

    function getTrade(){
        $arr=array(
            'uid'=>1,
        );
        $result=M('trade')->field('id','fuid','score','type','month','create_time')->where($arr)->select();
        //var_dump($result);
        if($result){
           foreach ($result as $val) {
               if($val['month']=201611){
                   $one=$val;
               }
               if($val['month']=201610){
                   $two=$val;
               }
           }

        }
    }
}